home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
emacs
/
emacs1857
/
bin_d2.zoo
/
lisp
/
terminal.el
< prev
next >
Wrap
Lisp/Scheme
|
1991-12-02
|
39KB
|
1,145 lines
;; Terminal emulator for GNU Emacs.
;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
;; Written by Richard Mlynarik, November 1986.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 1, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;;>>TODO
;;>> terminfo?
;;>> ** Nothing can be done about emacs' meta-lossage **
;;>> (without redoing keymaps `sanely' -- ask Mly for details)
;;>> One probably wants to do setenv MORE -c when running with
;;>> more-processing enabled.
(provide 'terminal)
(require 'ehelp)
(defvar terminal-escape-char ?\C-^
"*All characters except for this are passed verbatim through the
terminal-emulator. This character acts as a prefix for commands
to the emulator program itself. Type this character twice to send
it through the emulator. Type ? after typing it for a list of
possible commands.
This variable is local to each terminal-emulator buffer.")
(defvar terminal-scrolling t
"*If non-nil, the terminal-emulator will `scroll' when output occurs
past the bottom of the screen. If nil, output will `wrap' to the top
of the screen.
This variable is local to each terminal-emulator buffer.")
(defvar terminal-more-processing t
"*If non-nil, do more-processing.
This variable is local to each terminal-emulator buffer.")
;; If you are the sort of loser who uses scrolling without more breaks
;; and expects to actually see anything, you should probably set this to
;; around 400
(defvar terminal-redisplay-interval 5000
"*Maximum number of characters which will be processed by the
terminal-emulator before a screen redisplay is forced.
Set this to a large value for greater throughput,
set it smaller for more frequent updates but overall slower
performance.")
(defvar terminal-more-break-insertion
"*** More break -- Press space to continue ***")
(defvar terminal-escape-map nil)
(defvar terminal-map nil)
(defvar terminal-more-break-map nil)
(if terminal-map
nil
(let ((map (make-keymap)))
(fillarray map 'te-pass-through)
;(define-key map "\C-l"
; '(lambda () (interactive) (te-pass-through) (redraw-display)))
(setq terminal-map map)))
;(setq terminal-escape-map nil)
(if terminal-escape-map
nil
(let ((map (make-keymap)))
;(fillarray map 'te-escape-extended-command-unread)
(fillarray map 'undefined)
(let ((s "0"))
(while (<= (aref s 0) ?9)
(define-key map s 'digit-argument)
(aset s 0 (1+ (aref s 0)))))
(define-key map "b" 'switch-to-buffer)
(define-key map "o" 'other-window)
(define-key map "e" 'te-set-escape-char)
(define-key map "\C-l" 'redraw-display)
(define-key map "\C-o" 'te-flush-pending-output)
(define-key map "m" 'te-toggle-more-processing)
(define-key map "x" 'te-escape-extended-command)
(define-key map "?" 'te-escape-help)
(define-key map (char-to-string help-char) 'te-escape-help)
(setq terminal-escape-map map)))
(defvar te-escape-command-alist ())
;(setq te-escape-command-alist ())
(if te-escape-command-alist
nil
(setq te-escape-command-alist
'(("Set Escape Character" . te-set-escape-char)
("Refresh" . redraw-display)
("Record Output" . te-set-output-log)
("Photo" . te-set-output-log)
("Tofu" . te-tofu) ;; confuse the uninitiated
("Stuff Input" . te-stuff-string)
("Flush Pending Output" . te-flush-pending-output)
("Enable More Processing" . te-enable-more-processing)
("Disable More Processing" . te-disable-more-processing)
("Scroll at end of page" . te-do-scrolling)
("Wrap at end of page" . te-do-wrapping)
("Switch To Buffer" . switch-to-buffer)
("Other Window" . other-window)
("Kill Buffer" . kill-buffer)
("Help" . te-escape-help)
("Set Redisplay Interval" . te-set-redisplay-interval)
)))
;(setq terminal-more-break-map nil)
(if terminal-more-break-map
nil
(let ((map (make-keymap)))
(fillarray map 'te-more-break-unread)
(define-key map (char-to-string help-char) 'te-more-break-help)
(define-key map " " 'te-more-break-resume)
(define-key map "\C-l" 'redraw-display)
(define-key map "\C-o" 'te-more-break-flush-pending-output)
;;>>> this isn't right
;(define-key map "\^?" 'te-more-break-flush-pending-output) ;DEL
(define-key map "\r" 'te-more-break-advance-one-line)
(setq terminal-more-break-map map)))
;;;; escape map
(defun te-escape ()
(interactive)
(let (s
(local (current-local-map))
(global (current-global-map)))
(unwind-protect
(progn
(use-global-map terminal-escape-map)
(use-local-map terminal-escape-map)
(setq s (read-key-sequence
(if prefix-arg
(format "Emacs Terminal escape> %d "
(prefix-numeric-value prefix-arg))
"Emacs Terminal escape> "))))
(use-global-map global)
(use-local-map local))
(message "")
(cond ((string= s (make-string 1 terminal-escape-char))
(setq last-command-char terminal-escape-char)
(let ((terminal-escape-char -259))
(te-pass-through)))
((setq s (lookup-key terminal-escape-map s))
(call-interactively s)))))
(defun te-escape-help ()
"Provide help on commands available after terminal-escape-char is typed."
(interactive)
(message "Terminal emulator escape help...")
(let ((char (single-key-description terminal-escape-char)))
(with-electric-help
(function (lambda ()
(princ (format "Terminal-emulator escape, invoked by \"%s\"
Type \"%s\" twice to send a single \"%s\" through.
Other chars following \"%s\" are interpreted as follows:\n"
char char char char))
(princ (substitute-command-keys "\\{terminal-escape-map}\n"))
(princ (format "\nSubcommands of \"%s\" (%s)\n"
(where-is-internal 'te-escape-extended-command
terminal-escape-map t)
'te-escape-extended-command))
(let ((l (if (fboundp 'sortcar)
(sortcar (copy-sequence te-escape-command-alist)
'string<)
(sort (copy-sequence te-escape-command-alist)
(function (lambda (a b)
(string< (car a) (car b))))))))
(while l
(let ((doc (or (documentation (cdr (car l)))
"Not documented")))
(if (string-match "\n" doc)
;; just use first line of documentation
(setq doc (substring doc 0 (match-beginning 0))))
(princ " \"")
(princ (car (car l)))
(princ "\":\n ")
(princ doc)
(write-char ?\n))
(setq l (cdr l))))
nil)))))
(defun te-escape-extended-command ()
(interactive)
(let ((c (let ((completion-ignore-case t))
(completing-read "terminal command: "
te-escape-command-alist
nil t))))
(if c
(catch 'foo
(setq c (downcase c))
(let ((l te-escape-command-alist))
(while l
(if (string= c (downcase (car (car l))))
(throw 'foo (call-interactively (cdr (car l))))
(setq l (cdr l)))))))))
;; not used.
(defun te-escape-extended-command-unread ()
(interactive)
(setq unread-command-char last-input-char)
(te-escape-extended-command))
(defun te-set-escape-char (c)
"Change the terminal-emulator escape character."
(interactive "cSet escape character to: ")
(let ((o terminal-escape-char))
(message (if (= o c)
"\"%s\" is escape char"
"\"%s\" is now escape; \"%s\" passes though")
(single-key-description c)
(single-key-description o))
(setq terminal-escape-char c)))
(defun te-stuff-string (string)
"Read a string to send to through the terminal emulator
as though that string had been typed on the keyboard.
Very poor man's file transfer protocol."
(interactive "sStuff string: ")